import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;




public class Client {
	
	private String host; 
	private int port ;
	private Socket socket;
	
	public Client(String host,int port) throws IOException{
		socket = new Socket(host,port);
	}

	
	private PrintWriter getWriter(Socket socket) throws IOException{
		OutputStream os = socket.getOutputStream();
		return new PrintWriter(os,true);
	}
	
	private BufferedReader getReader(Socket socket) throws IOException{
		InputStream is = socket.getInputStream();
		return new BufferedReader(new InputStreamReader(is));
	}
	private BufferedReader getClientInput(){
		return new BufferedReader(new InputStreamReader(System.in));
	}
	public void talk() throws IOException{
		
		try{
			PrintWriter out = getWriter(socket);
			BufferedReader in = getReader(socket);
			BufferedReader client = getClientInput();
			String msg = null;
			while((msg = client.readLine()) != null){
				out.println(msg);
				System.out.println(in.readLine());
				if (msg.equals("bye")) break;
			}
		}catch(IOException e){
			e.printStackTrace();
		}finally{
			socket.close();
		}
	}
	public static void main(String[] args) throws IOException{
		
		new Client("localhost",8888).talk();
		
	}
}
